// pages/login/login.js
let app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  doLogin:function (e) {
    console.log(e.detail.errmsg);
    console.log(e.detail.userInfo);
    console.log(e.detail.rawData);
    
    wx.login({
      success: function (res) {
        console.log(res);
        var code = res.code
        var url = app.data.globalUrl.projectUrl+"/wxLogin";
        wx.request({
          url: url,
          method:"POST",
          data:{
            code:code
          },
          header: {
            'content-type': 'application/x-www-form-urlencoded' // 默认值
          },
          success: function(result) {
            console.log(result);
           if(result.data.status==200){
             wx.showToast({
               title: '登录成功',
               icon:'none'
             })
             app.setGlobalUserInfo(e.detail.userInfo)
           }else{
             wx.showToast({
               title: '登录失败',
               icon: 'none'
             })
           }
            wx.switchTab({
              url: '/pages/index/index'
            })
            
          }
        })
      }
    })
  }


})